package cn.stylefeng.guns.modular.rest;


import cn.stylefeng.guns.comm.util.DictTypeConstant;
import cn.stylefeng.guns.modular.school.entity.ClassInfo;
import cn.stylefeng.guns.modular.school.entity.StudentGuardian;
import cn.stylefeng.guns.modular.school.entity.StudentInfo;
import cn.stylefeng.guns.modular.school.model.params.ClassMsgParam;
import cn.stylefeng.guns.modular.school.model.params.ClassTeacherLessionParam;
import cn.stylefeng.guns.modular.school.model.result.ClassMsgResult;
import cn.stylefeng.guns.modular.school.model.result.ClassTeacherLessionResult;
import cn.stylefeng.guns.modular.school.service.*;
import cn.stylefeng.guns.sys.core.constant.factory.ConstantFactory;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ErrorResponseData;
import cn.stylefeng.roses.core.reqres.response.SuccessResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 轮播图控制器
 *
 * @author
 * @Date 2019-11-18 13:24:11
 */
@RestController
@RequestMapping("/gunsApi/class/msg")
public class ApiNeedTokenClassMsgController extends BaseController {
    private final StudentInfoService studentInfoService;
    private final ClassInfoService classInfoService;
    private final ClassMsgService classMsgService;
    private final ClassTeacherLessionService classTeacherLessionService;

    @Autowired
    public ApiNeedTokenClassMsgController(ClassMsgService classMsgService, ClassInfoService classInfoService, StudentInfoService studentInfoService,ClassTeacherLessionService classTeacherLessionService) {
        this.classMsgService = classMsgService;
        this.classInfoService = classInfoService;
        this.studentInfoService = studentInfoService;
        this.classTeacherLessionService = classTeacherLessionService;
    }

    /**
     * 根据code找班级通知
     */
    @RequestMapping(value = "/list")
    public Object list(String studentCode) {
        Map map = new HashMap();
        SuccessResponseData SUCCESS_TIP = new SuccessResponseData();
        // 学生信息
        StudentInfo studentInfo = studentInfoService.findByCode(studentCode);
        if (studentInfo == null) {
            return new ErrorResponseData(500, "学号错误！");
        }
        // 班级信息
        ClassInfo classInfo = classInfoService.getById(studentInfo.getClassId());
        // 班级通知
        ClassMsgParam param = new ClassMsgParam();
        param.setClassId(classInfo.getId());
        param.setDisplayFlag("0");
        List<ClassMsgResult> classMsgResultList = classMsgService.findListBySpec(param);
        ClassTeacherLessionParam classTeacherLessionParam = new ClassTeacherLessionParam();
        classMsgResultList.forEach(classMsgResult -> {
            Integer teacherId = classMsgResult.getTeacherId();
            classTeacherLessionParam.setTeacherId(teacherId);
            classTeacherLessionParam.setClassId(classInfo.getId());
            ClassTeacherLessionResult classTeacherLessionResult = classTeacherLessionService.findBySpec(classTeacherLessionParam);
            String lessonName = ConstantFactory.me().getDictsByName("课程", classTeacherLessionResult.getLessionId());
            classMsgResult.setLessionName(lessonName);

        });
        map.put("classMsgResultList", classMsgResultList);

        SUCCESS_TIP.setData(map);
        return SUCCESS_TIP;
    }

}


